{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from bertopic import BERTopic\n",
    "from ckiptagger import construct_dictionary, WS, POS, NER\n",
    "from transformers import AutoModelForTokenClassification\n",
    "import numpy as np\n",
    "import random\n",
    "import torch"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "def set_seed(seed: int) -> None:\n",
    "  random.seed(seed)\n",
    "  np.random.seed(seed)\n",
    "  torch.manual_seed(seed)\n",
    "  torch.cuda.manual_seed_all(seed)\n",
    "\n",
    "  if torch.cuda.is_available():\n",
    "    # Disable cuDNN benchmark for deterministic selection on algorithm.\n",
    "    torch.backends.cudnn.benchmark = False\n",
    "    torch.backends.cudnn.deterministic = True\n",
    "  \n",
    "set_seed(4698)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "南韓\n"
     ]
    }
   ],
   "source": [
    "keysfile = \"data/keys.txt\"\n",
    "with open(keysfile) as file:\n",
    "    lines = file.read().splitlines() \n",
    "\n",
    "print(lines[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "keydict = { l: 1 for l in lines}\n",
    "dictionary = construct_dictionary(keydict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-04-10 13:31:21.802783: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:375] MLIR V1 optimization pass is not enabled\n"
     ]
    }
   ],
   "source": [
    "ws = WS(\"./data\")\n",
    "pos = POS(\"./data\")\n",
    "ner = NER(\"./data\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_csv(\"data/data.csv\")\n",
    "df = df[[\"year\", \"name\", \"label\", \"description\"]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "stoptext = open('data/stopword.txt', encoding='utf-8').read()\n",
    "stopwords = stoptext.split('\\n')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "sentence_list = df[\"description\"].tolist()\n",
    "word_sentence_list = ws(\n",
    "    sentence_list,\n",
    "    sentence_segmentation = True, # To consider delimiters\n",
    "    segment_delimiter_set = {\",\", \"。\", \":\", \"?\", \"!\", \";\"}, # This is the defualt set of delimiters\n",
    "    recommend_dictionary = dictionary # words in this dictionary are encouraged    \n",
    ")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 轉換為BERTopic 可接受格式\n",
    "ws = [\" \".join(w) for w in word_sentence_list]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-04-10 13:34:52,128 - BERTopic - Embedding - Transforming documents to embeddings.\n",
      "Batches: 100%|██████████| 99/99 [00:37<00:00,  2.67it/s]\n",
      "2024-04-10 13:35:32,437 - BERTopic - Embedding - Completed ✓\n",
      "2024-04-10 13:35:32,438 - BERTopic - Dimensionality - Fitting the dimensionality reduction algorithm\n",
      "2024-04-10 13:35:41,960 - BERTopic - Dimensionality - Completed ✓\n",
      "2024-04-10 13:35:41,960 - BERTopic - Cluster - Start clustering the reduced embeddings\n",
      "2024-04-10 13:35:42,022 - BERTopic - Cluster - Completed ✓\n",
      "2024-04-10 13:35:42,026 - BERTopic - Representation - Extracting topics from clusters using representation models.\n",
      "2024-04-10 13:35:42,353 - BERTopic - Representation - Completed ✓\n"
     ]
    }
   ],
   "source": [
    "model = AutoModelForTokenClassification.from_pretrained(\"ckiplab/bert-base-chinese-ws\")\n",
    "topic_model = BERTopic(\n",
    "    language=\"chinese\", \n",
    "    embedding_model=model,  \n",
    "    verbose=True\n",
    ")\n",
    "topics, probs = topic_model.fit_transform(ws)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "timestamps = df.year.tolist()  # 讀取data.csv檔案中的 year 資料，作為我們的timestamp\n",
    "timestamps = [f\"{str(int(t)+1911)}-01-01\" for t in timestamps]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "0it [00:00, ?it/s]"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "8it [00:01,  4.88it/s]\n"
     ]
    },
    {
     "data": {
      "application/vnd.plotly.v1+json": {
       "config": {
        "plotlyServerURL": "https://plot.ly"
       },
       "data": [
        {
         "hoverinfo": "text",
         "hovertext": [
          "<b>Topic 0</b><br>Words: 臨床試驗, 計畫, 研究, 開發, 進行",
          "<b>Topic 0</b><br>Words: 疫苗, 計畫, 臨床試驗, 開發, 發展",
          "<b>Topic 0</b><br>Words: 生技, 臨床試驗, 計畫, 研發, 發展",
          "<b>Topic 0</b><br>Words: 新藥, 生技, 中心, 計畫, 疾病",
          "<b>Topic 0</b><br>Words: 中心, 計畫, 生技, 進行, 研發",
          "<b>Topic 0</b><br>Words: 計畫, 中心, 臨床試驗, 開發, 生技",
          "<b>Topic 0</b><br>Words: 計畫, 臨床試驗, 中心, 開發, 發展",
          "<b>Topic 0</b><br>Words: 開發, 中心, 計畫, 研發, 發展"
         ],
         "marker": {
          "color": "#E69F00"
         },
         "mode": "lines",
         "name": "0_計畫_臨床試驗_中心_開發",
         "type": "scatter",
         "x": [
          "2014-01-01T00:00:00",
          "2015-01-01T00:00:00",
          "2016-01-01T00:00:00",
          "2017-01-01T00:00:00",
          "2018-01-01T00:00:00",
          "2019-01-01T00:00:00",
          "2020-01-01T00:00:00",
          "2021-01-01T00:00:00"
         ],
         "y": [
          44,
          48,
          35,
          35,
          42,
          40,
          38,
          48
         ]
        },
        {
         "hoverinfo": "text",
         "hovertext": [
          "<b>Topic 1</b><br>Words: 智慧電子, 智慧, 服務, 發展, 產業",
          "<b>Topic 1</b><br>Words: 智慧, 智慧電子, 應用, 發展, 產業",
          "<b>Topic 1</b><br>Words: 智慧, 服務, 智財, 平台, 發展",
          "<b>Topic 1</b><br>Words: 智財, 智慧, 服務, 產業, 發展",
          "<b>Topic 1</b><br>Words: 智慧, 服務, 發展, 應用, 產業",
          "<b>Topic 1</b><br>Words: 智慧, 產業, 發展, 服務, 推動",
          "<b>Topic 1</b><br>Words: 智慧, 發展, 應用, 服務, 產業",
          "<b>Topic 1</b><br>Words: 智慧, 5g, 應用, 發展, 產業"
         ],
         "marker": {
          "color": "#56B4E9"
         },
         "mode": "lines",
         "name": "1_智慧_服務_發展_產業",
         "type": "scatter",
         "x": [
          "2014-01-01T00:00:00",
          "2015-01-01T00:00:00",
          "2016-01-01T00:00:00",
          "2017-01-01T00:00:00",
          "2018-01-01T00:00:00",
          "2019-01-01T00:00:00",
          "2020-01-01T00:00:00",
          "2021-01-01T00:00:00"
         ],
         "y": [
          20,
          20,
          22,
          34,
          39,
          43,
          39,
          54
         ]
        },
        {
         "hoverinfo": "text",
         "hovertext": [
          "<b>Topic 2</b><br>Words: 中子, 工商, 行政, 地震, 實驗",
          "<b>Topic 2</b><br>Words: 中子, 行政, 工商, 實驗, 頻道",
          "<b>Topic 2</b><br>Words: 中子, 人事, 研發成果, 實驗, 行政",
          "<b>Topic 2</b><br>Words: 中子, 行政, 電視臺, 協助, 訊號",
          "<b>Topic 2</b><br>Words: 中子, 頻寬, 行政, 電視臺, 訊號",
          "<b>Topic 2</b><br>Words: 頻寬, 電視臺, 行政, 訊號, mbps",
          "<b>Topic 2</b><br>Words: 頻寬, 訊號, 電視臺, 上鏈, 測謊",
          "<b>Topic 2</b><br>Words: 訊號, 電視臺, 上鏈, 接收, 頻道"
         ],
         "marker": {
          "color": "#009E73"
         },
         "mode": "lines",
         "name": "2_中子_行政_頻道_實驗",
         "type": "scatter",
         "x": [
          "2014-01-01T00:00:00",
          "2015-01-01T00:00:00",
          "2016-01-01T00:00:00",
          "2017-01-01T00:00:00",
          "2018-01-01T00:00:00",
          "2019-01-01T00:00:00",
          "2020-01-01T00:00:00",
          "2021-01-01T00:00:00"
         ],
         "y": [
          19,
          20,
          24,
          27,
          20,
          16,
          16,
          13
         ]
        },
        {
         "hoverinfo": "text",
         "hovertext": [
          "<b>Topic 3</b><br>Words: 食品, pki, 美食, 食媒性, 病原",
          "<b>Topic 3</b><br>Words: 食品, 食媒性, 加工技術, 品牌, 食品安全",
          "<b>Topic 3</b><br>Words: 食品, 食品產業, 食媒性, 食品安全, 開發",
          "<b>Topic 3</b><br>Words: 食品, 食品產業, 食媒性, 食品安全, 食材",
          "<b>Topic 3</b><br>Words: 食品, 食品產業, 食材, 校園午餐, 加工技術",
          "<b>Topic 3</b><br>Words: 食品, 食品產業, 食材, 開發, 國產",
          "<b>Topic 3</b><br>Words: 食品, 食品產業, 肥胖, 食材, 氣候變遷",
          "<b>Topic 3</b><br>Words: 食品, 品質, 透過, 食品產業, 食品安全"
         ],
         "marker": {
          "color": "#F0E442"
         },
         "mode": "lines",
         "name": "3_食品_食品產業_食品安全_食材",
         "type": "scatter",
         "x": [
          "2014-01-01T00:00:00",
          "2015-01-01T00:00:00",
          "2016-01-01T00:00:00",
          "2017-01-01T00:00:00",
          "2018-01-01T00:00:00",
          "2019-01-01T00:00:00",
          "2020-01-01T00:00:00",
          "2021-01-01T00:00:00"
         ],
         "y": [
          10,
          8,
          12,
          17,
          12,
          10,
          11,
          9
         ]
        },
        {
         "hoverinfo": "text",
         "hovertext": [
          "<b>Topic 4</b><br>Words: 低溫物流, 園區, 工業, 基礎, 智財",
          "<b>Topic 4</b><br>Words: 石化, 專利布局, 智財, 材料, 高值化",
          "<b>Topic 4</b><br>Words: 材料, 石化, 超高畫質, 技術, 基礎",
          "<b>Topic 4</b><br>Words: 超高畫質, 石化, 製作, 商務, 產業",
          "<b>Topic 4</b><br>Words: 超高畫質, 高階, 高速寬頻, 基礎, 高值化",
          "<b>Topic 4</b><br>Words: 超高畫質, 基礎, 高階, 技術, 設備",
          "<b>Topic 4</b><br>Words: 高速寬頻, 網路, 高值化, 自製, 高階",
          "<b>Topic 4</b><br>Words: 農業素材, 產業, 碳材, 高值化, 基地臺"
         ],
         "marker": {
          "color": "#D55E00"
         },
         "mode": "lines",
         "name": "4_超高畫質_基礎_產業_技術",
         "type": "scatter",
         "x": [
          "2014-01-01T00:00:00",
          "2015-01-01T00:00:00",
          "2016-01-01T00:00:00",
          "2017-01-01T00:00:00",
          "2018-01-01T00:00:00",
          "2019-01-01T00:00:00",
          "2020-01-01T00:00:00",
          "2021-01-01T00:00:00"
         ],
         "y": [
          10,
          8,
          11,
          9,
          10,
          13,
          10,
          8
         ]
        },
        {
         "hoverinfo": "text",
         "hovertext": [
          "<b>Topic 5</b><br>Words: 地下水, 都會區, 山區, 水文觀測, 防洪",
          "<b>Topic 5</b><br>Words: 地下水, 水資源, 都會區, 水文觀測, 補注區",
          "<b>Topic 5</b><br>Words: 地下水, 混凝土, 綠色水泥, 氣候變遷, 水文觀測",
          "<b>Topic 5</b><br>Words: 地下水, 氣候變遷, 水資源, 水文觀測, 混凝土",
          "<b>Topic 5</b><br>Words: 混凝土, 地下水, 綠色水泥, 水庫, 水資源",
          "<b>Topic 5</b><br>Words: 地下水, 混凝土, 飲用水, 用水, 水庫",
          "<b>Topic 5</b><br>Words: 地下水, 水資源, 用水, 給水, 飲用水",
          "<b>Topic 5</b><br>Words: 飲用水, 地層下陷, 水庫, 地下水, 列管"
         ],
         "marker": {
          "color": "#0072B2"
         },
         "mode": "lines",
         "name": "5_地下水_混凝土_水資源_氣候變遷",
         "type": "scatter",
         "x": [
          "2014-01-01T00:00:00",
          "2015-01-01T00:00:00",
          "2016-01-01T00:00:00",
          "2017-01-01T00:00:00",
          "2018-01-01T00:00:00",
          "2019-01-01T00:00:00",
          "2020-01-01T00:00:00",
          "2021-01-01T00:00:00"
         ],
         "y": [
          9,
          8,
          10,
          11,
          8,
          8,
          8,
          7
         ]
        },
        {
         "hoverinfo": "text",
         "hovertext": [
          "<b>Topic 6</b><br>Words: 儀器, 光學, 光源, 材料, 真空",
          "<b>Topic 6</b><br>Words: 儀器, 光源, 光學, 材料, 光束線",
          "<b>Topic 6</b><br>Words: 光源, 儀器, 光學, 半導體, 設施",
          "<b>Topic 6</b><br>Words: 光束線, 光源, 光子源, 設施, 實驗",
          "<b>Topic 6</b><br>Words: 光子源, 光源, 光束線, 設施, 台灣",
          "<b>Topic 6</b><br>Words: 儀器, 光子源, 設施, 實驗, 光學",
          "<b>Topic 6</b><br>Words: 設施, 實驗, 光子源, 光源, 顯微術",
          "<b>Topic 6</b><br>Words: 光子源, 實驗, 光源, 用戶, 台灣"
         ],
         "marker": {
          "color": "#CC79A7"
         },
         "mode": "lines",
         "name": "6_光源_光子源_設施_光束線",
         "type": "scatter",
         "x": [
          "2014-01-01T00:00:00",
          "2015-01-01T00:00:00",
          "2016-01-01T00:00:00",
          "2017-01-01T00:00:00",
          "2018-01-01T00:00:00",
          "2019-01-01T00:00:00",
          "2020-01-01T00:00:00",
          "2021-01-01T00:00:00"
         ],
         "y": [
          8,
          10,
          10,
          8,
          6,
          7,
          5,
          5
         ]
        },
        {
         "hoverinfo": "text",
         "hovertext": [
          "<b>Topic 7</b><br>Words: 未來想像, 核心能力, 課程, 人文, 軟體",
          "<b>Topic 7</b><br>Words: 人文, 社科, 學術, 人文社會, 資料庫",
          "<b>Topic 7</b><br>Words: 人文, 社會科學, 服務業, 領域, 社會企業",
          "<b>Topic 7</b><br>Words: 人文, 社會科學, 圖書館, 領域, 服務業",
          "<b>Topic 7</b><br>Words: 人文, 社會科學, 領域, 圖書館, 數位經濟",
          "<b>Topic 7</b><br>Words: 新住民, 領域, 新創, 敘事力, 計畫",
          "<b>Topic 7</b><br>Words: 社會創新, 社會福利, 新住民, 跨域, 分支",
          "<b>Topic 7</b><br>Words: 社會創新, 社會福利, 分支, 志願服務, 前瞻議題"
         ],
         "marker": {
          "color": "#E69F00"
         },
         "mode": "lines",
         "name": "7_人文_社會科學_社會創新_領域",
         "type": "scatter",
         "x": [
          "2014-01-01T00:00:00",
          "2015-01-01T00:00:00",
          "2016-01-01T00:00:00",
          "2017-01-01T00:00:00",
          "2018-01-01T00:00:00",
          "2019-01-01T00:00:00",
          "2020-01-01T00:00:00",
          "2021-01-01T00:00:00"
         ],
         "y": [
          5,
          5,
          6,
          6,
          6,
          7,
          8,
          6
         ]
        },
        {
         "hoverinfo": "text",
         "hovertext": [
          "<b>Topic 8</b><br>Words: 交通資訊, 車輛, 開發, 大型, 系統",
          "<b>Topic 8</b><br>Words: 車輛, 模組, 大型, 鋰電池, 系統",
          "<b>Topic 8</b><br>Words: 車輛, 大型, 鋰電池, 高能量, 模組",
          "<b>Topic 8</b><br>Words: 車輛, 自行車, 模組, 運輸, 技術",
          "<b>Topic 8</b><br>Words: 駕駛車, 車輛, 自動, 運輸, 自行車",
          "<b>Topic 8</b><br>Words: 雷達, 高精度, 車輛, 地圖, 自駕",
          "<b>Topic 8</b><br>Words: 車輛, 車牌辨識, kr, 車廠, 雷達",
          "<b>Topic 8</b><br>Words: 自駕, 車牌辨識, 車輛, 漁船, 雷達"
         ],
         "marker": {
          "color": "#56B4E9"
         },
         "mode": "lines",
         "name": "8_車輛_模組_大型_系統",
         "type": "scatter",
         "x": [
          "2014-01-01T00:00:00",
          "2015-01-01T00:00:00",
          "2016-01-01T00:00:00",
          "2017-01-01T00:00:00",
          "2018-01-01T00:00:00",
          "2019-01-01T00:00:00",
          "2020-01-01T00:00:00",
          "2021-01-01T00:00:00"
         ],
         "y": [
          10,
          8,
          4,
          4,
          7,
          5,
          5,
          5
         ]
        },
        {
         "hoverinfo": "text",
         "hovertext": [
          "<b>Topic 9</b><br>Words: 山崩, 山崩潛勢, 防災教育, 耐震評估, 活動斷層",
          "<b>Topic 9</b><br>Words: 山崩潛勢, 研發成果, 山崩, 輻射監測, 斷層",
          "<b>Topic 9</b><br>Words: 活動斷層, 山崩潛勢, 山崩, 斷層, 研發成果",
          "<b>Topic 9</b><br>Words: 崩塌, 大規模, 山崩, 山崩潛勢, 活動斷層",
          "<b>Topic 9</b><br>Words: 開源, 研發成果, 農地, 開發, 耐震評估",
          "<b>Topic 9</b><br>Words: 研發成果, 農地, 災害韌性, 模型, 大量估價",
          "<b>Topic 9</b><br>Words: 農地, 災害韌性, 農業區, 資訊, 地價",
          "<b>Topic 9</b><br>Words: 地熱, 探勘, 災害韌性, 潛能區, 農地"
         ],
         "marker": {
          "color": "#009E73"
         },
         "mode": "lines",
         "name": "9_研發成果_山崩_山崩潛勢_耐震評估",
         "type": "scatter",
         "x": [
          "2014-01-01T00:00:00",
          "2015-01-01T00:00:00",
          "2016-01-01T00:00:00",
          "2017-01-01T00:00:00",
          "2018-01-01T00:00:00",
          "2019-01-01T00:00:00",
          "2020-01-01T00:00:00",
          "2021-01-01T00:00:00"
         ],
         "y": [
          7,
          7,
          4,
          7,
          5,
          5,
          4,
          5
         ]
        },
        {
         "hoverinfo": "text",
         "hovertext": [
          "<b>Topic 10</b><br>Words: 研究, 有害生物, 植物, 動物用, 安全衛生",
          "<b>Topic 10</b><br>Words: 研究, 環境毒物, 檢疫, 有害生物, 安全衛生",
          "<b>Topic 10</b><br>Words: 子項, 審驗技術, 研究, 處置, 廢棄物",
          "<b>Topic 10</b><br>Words: 子項, 審驗技術, 研究, 廢棄物, 處置",
          "<b>Topic 10</b><br>Words: 研究, 廢棄物, 子項, 審驗技術, 低放射性",
          "<b>Topic 10</b><br>Words: 研究, 廢棄物, 子項, 低放射性, 處置",
          "<b>Topic 10</b><br>Words: 研究, 勞動, 廢棄物, 資材, 處置",
          "<b>Topic 10</b><br>Words: 勞動, 職業安全, 衛生, 研究, 職場安全"
         ],
         "marker": {
          "color": "#F0E442"
         },
         "mode": "lines",
         "name": "10_研究_廢棄物_子項_勞動",
         "type": "scatter",
         "x": [
          "2014-01-01T00:00:00",
          "2015-01-01T00:00:00",
          "2016-01-01T00:00:00",
          "2017-01-01T00:00:00",
          "2018-01-01T00:00:00",
          "2019-01-01T00:00:00",
          "2020-01-01T00:00:00",
          "2021-01-01T00:00:00"
         ],
         "y": [
          4,
          4,
          5,
          7,
          7,
          7,
          8,
          1
         ]
        },
        {
         "hoverinfo": "text",
         "hovertext": [
          "<b>Topic 11</b><br>Words: 海洋, 海洋科技, 探測, 地震, 海嘯",
          "<b>Topic 11</b><br>Words: 海洋, 海洋科技, 探測, 研究船, 水合物",
          "<b>Topic 11</b><br>Words: 海洋, 探測, 海洋科技, 地震, 海域",
          "<b>Topic 11</b><br>Words: 海洋, 海洋科技, 海域, 地震, 公里",
          "<b>Topic 11</b><br>Words: 海洋, 海洋科技, 南海, 海象, 海域",
          "<b>Topic 11</b><br>Words: 海洋, 海洋科技, 海洋環境, 研究船, 船舶",
          "<b>Topic 11</b><br>Words: 災防, 海象, 海洋, 海域, 氣象",
          "<b>Topic 11</b><br>Words: 海洋, 海象, 海洋科技, 海域, 空運"
         ],
         "marker": {
          "color": "#D55E00"
         },
         "mode": "lines",
         "name": "11_海洋_海洋科技_海域_探測",
         "type": "scatter",
         "x": [
          "2014-01-01T00:00:00",
          "2015-01-01T00:00:00",
          "2016-01-01T00:00:00",
          "2017-01-01T00:00:00",
          "2018-01-01T00:00:00",
          "2019-01-01T00:00:00",
          "2020-01-01T00:00:00",
          "2021-01-01T00:00:00"
         ],
         "y": [
          6,
          7,
          5,
          7,
          5,
          5,
          3,
          4
         ]
        }
       ],
       "layout": {
        "height": 450,
        "hoverlabel": {
         "bgcolor": "white",
         "font": {
          "family": "Rockwell",
          "size": 16
         }
        },
        "legend": {
         "title": {
          "text": "<b>Global Topic Representation"
         }
        },
        "template": {
         "data": {
          "bar": [
           {
            "error_x": {
             "color": "rgb(36,36,36)"
            },
            "error_y": {
             "color": "rgb(36,36,36)"
            },
            "marker": {
             "line": {
              "color": "white",
              "width": 0.5
             },
             "pattern": {
              "fillmode": "overlay",
              "size": 10,
              "solidity": 0.2
             }
            },
            "type": "bar"
           }
          ],
          "barpolar": [
           {
            "marker": {
             "line": {
              "color": "white",
              "width": 0.5
             },
             "pattern": {
              "fillmode": "overlay",
              "size": 10,
              "solidity": 0.2
             }
            },
            "type": "barpolar"
           }
          ],
          "carpet": [
           {
            "aaxis": {
             "endlinecolor": "rgb(36,36,36)",
             "gridcolor": "white",
             "linecolor": "white",
             "minorgridcolor": "white",
             "startlinecolor": "rgb(36,36,36)"
            },
            "baxis": {
             "endlinecolor": "rgb(36,36,36)",
             "gridcolor": "white",
             "linecolor": "white",
             "minorgridcolor": "white",
             "startlinecolor": "rgb(36,36,36)"
            },
            "type": "carpet"
           }
          ],
          "choropleth": [
           {
            "colorbar": {
             "outlinewidth": 1,
             "tickcolor": "rgb(36,36,36)",
             "ticks": "outside"
            },
            "type": "choropleth"
           }
          ],
          "contour": [
           {
            "colorbar": {
             "outlinewidth": 1,
             "tickcolor": "rgb(36,36,36)",
             "ticks": "outside"
            },
            "colorscale": [
             [
              0,
              "#440154"
             ],
             [
              0.1111111111111111,
              "#482878"
             ],
             [
              0.2222222222222222,
              "#3e4989"
             ],
             [
              0.3333333333333333,
              "#31688e"
             ],
             [
              0.4444444444444444,
              "#26828e"
             ],
             [
              0.5555555555555556,
              "#1f9e89"
             ],
             [
              0.6666666666666666,
              "#35b779"
             ],
             [
              0.7777777777777778,
              "#6ece58"
             ],
             [
              0.8888888888888888,
              "#b5de2b"
             ],
             [
              1,
              "#fde725"
             ]
            ],
            "type": "contour"
           }
          ],
          "contourcarpet": [
           {
            "colorbar": {
             "outlinewidth": 1,
             "tickcolor": "rgb(36,36,36)",
             "ticks": "outside"
            },
            "type": "contourcarpet"
           }
          ],
          "heatmap": [
           {
            "colorbar": {
             "outlinewidth": 1,
             "tickcolor": "rgb(36,36,36)",
             "ticks": "outside"
            },
            "colorscale": [
             [
              0,
              "#440154"
             ],
             [
              0.1111111111111111,
              "#482878"
             ],
             [
              0.2222222222222222,
              "#3e4989"
             ],
             [
              0.3333333333333333,
              "#31688e"
             ],
             [
              0.4444444444444444,
              "#26828e"
             ],
             [
              0.5555555555555556,
              "#1f9e89"
             ],
             [
              0.6666666666666666,
              "#35b779"
             ],
             [
              0.7777777777777778,
              "#6ece58"
             ],
             [
              0.8888888888888888,
              "#b5de2b"
             ],
             [
              1,
              "#fde725"
             ]
            ],
            "type": "heatmap"
           }
          ],
          "heatmapgl": [
           {
            "colorbar": {
             "outlinewidth": 1,
             "tickcolor": "rgb(36,36,36)",
             "ticks": "outside"
            },
            "colorscale": [
             [
              0,
              "#440154"
             ],
             [
              0.1111111111111111,
              "#482878"
             ],
             [
              0.2222222222222222,
              "#3e4989"
             ],
             [
              0.3333333333333333,
              "#31688e"
             ],
             [
              0.4444444444444444,
              "#26828e"
             ],
             [
              0.5555555555555556,
              "#1f9e89"
             ],
             [
              0.6666666666666666,
              "#35b779"
             ],
             [
              0.7777777777777778,
              "#6ece58"
             ],
             [
              0.8888888888888888,
              "#b5de2b"
             ],
             [
              1,
              "#fde725"
             ]
            ],
            "type": "heatmapgl"
           }
          ],
          "histogram": [
           {
            "marker": {
             "line": {
              "color": "white",
              "width": 0.6
             }
            },
            "type": "histogram"
           }
          ],
          "histogram2d": [
           {
            "colorbar": {
             "outlinewidth": 1,
             "tickcolor": "rgb(36,36,36)",
             "ticks": "outside"
            },
            "colorscale": [
             [
              0,
              "#440154"
             ],
             [
              0.1111111111111111,
              "#482878"
             ],
             [
              0.2222222222222222,
              "#3e4989"
             ],
             [
              0.3333333333333333,
              "#31688e"
             ],
             [
              0.4444444444444444,
              "#26828e"
             ],
             [
              0.5555555555555556,
              "#1f9e89"
             ],
             [
              0.6666666666666666,
              "#35b779"
             ],
             [
              0.7777777777777778,
              "#6ece58"
             ],
             [
              0.8888888888888888,
              "#b5de2b"
             ],
             [
              1,
              "#fde725"
             ]
            ],
            "type": "histogram2d"
           }
          ],
          "histogram2dcontour": [
           {
            "colorbar": {
             "outlinewidth": 1,
             "tickcolor": "rgb(36,36,36)",
             "ticks": "outside"
            },
            "colorscale": [
             [
              0,
              "#440154"
             ],
             [
              0.1111111111111111,
              "#482878"
             ],
             [
              0.2222222222222222,
              "#3e4989"
             ],
             [
              0.3333333333333333,
              "#31688e"
             ],
             [
              0.4444444444444444,
              "#26828e"
             ],
             [
              0.5555555555555556,
              "#1f9e89"
             ],
             [
              0.6666666666666666,
              "#35b779"
             ],
             [
              0.7777777777777778,
              "#6ece58"
             ],
             [
              0.8888888888888888,
              "#b5de2b"
             ],
             [
              1,
              "#fde725"
             ]
            ],
            "type": "histogram2dcontour"
           }
          ],
          "mesh3d": [
           {
            "colorbar": {
             "outlinewidth": 1,
             "tickcolor": "rgb(36,36,36)",
             "ticks": "outside"
            },
            "type": "mesh3d"
           }
          ],
          "parcoords": [
           {
            "line": {
             "colorbar": {
              "outlinewidth": 1,
              "tickcolor": "rgb(36,36,36)",
              "ticks": "outside"
             }
            },
            "type": "parcoords"
           }
          ],
          "pie": [
           {
            "automargin": true,
            "type": "pie"
           }
          ],
          "scatter": [
           {
            "fillpattern": {
             "fillmode": "overlay",
             "size": 10,
             "solidity": 0.2
            },
            "type": "scatter"
           }
          ],
          "scatter3d": [
           {
            "line": {
             "colorbar": {
              "outlinewidth": 1,
              "tickcolor": "rgb(36,36,36)",
              "ticks": "outside"
             }
            },
            "marker": {
             "colorbar": {
              "outlinewidth": 1,
              "tickcolor": "rgb(36,36,36)",
              "ticks": "outside"
             }
            },
            "type": "scatter3d"
           }
          ],
          "scattercarpet": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 1,
              "tickcolor": "rgb(36,36,36)",
              "ticks": "outside"
             }
            },
            "type": "scattercarpet"
           }
          ],
          "scattergeo": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 1,
              "tickcolor": "rgb(36,36,36)",
              "ticks": "outside"
             }
            },
            "type": "scattergeo"
           }
          ],
          "scattergl": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 1,
              "tickcolor": "rgb(36,36,36)",
              "ticks": "outside"
             }
            },
            "type": "scattergl"
           }
          ],
          "scattermapbox": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 1,
              "tickcolor": "rgb(36,36,36)",
              "ticks": "outside"
             }
            },
            "type": "scattermapbox"
           }
          ],
          "scatterpolar": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 1,
              "tickcolor": "rgb(36,36,36)",
              "ticks": "outside"
             }
            },
            "type": "scatterpolar"
           }
          ],
          "scatterpolargl": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 1,
              "tickcolor": "rgb(36,36,36)",
              "ticks": "outside"
             }
            },
            "type": "scatterpolargl"
           }
          ],
          "scatterternary": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 1,
              "tickcolor": "rgb(36,36,36)",
              "ticks": "outside"
             }
            },
            "type": "scatterternary"
           }
          ],
          "surface": [
           {
            "colorbar": {
             "outlinewidth": 1,
             "tickcolor": "rgb(36,36,36)",
             "ticks": "outside"
            },
            "colorscale": [
             [
              0,
              "#440154"
             ],
             [
              0.1111111111111111,
              "#482878"
             ],
             [
              0.2222222222222222,
              "#3e4989"
             ],
             [
              0.3333333333333333,
              "#31688e"
             ],
             [
              0.4444444444444444,
              "#26828e"
             ],
             [
              0.5555555555555556,
              "#1f9e89"
             ],
             [
              0.6666666666666666,
              "#35b779"
             ],
             [
              0.7777777777777778,
              "#6ece58"
             ],
             [
              0.8888888888888888,
              "#b5de2b"
             ],
             [
              1,
              "#fde725"
             ]
            ],
            "type": "surface"
           }
          ],
          "table": [
           {
            "cells": {
             "fill": {
              "color": "rgb(237,237,237)"
             },
             "line": {
              "color": "white"
             }
            },
            "header": {
             "fill": {
              "color": "rgb(217,217,217)"
             },
             "line": {
              "color": "white"
             }
            },
            "type": "table"
           }
          ]
         },
         "layout": {
          "annotationdefaults": {
           "arrowhead": 0,
           "arrowwidth": 1
          },
          "autotypenumbers": "strict",
          "coloraxis": {
           "colorbar": {
            "outlinewidth": 1,
            "tickcolor": "rgb(36,36,36)",
            "ticks": "outside"
           }
          },
          "colorscale": {
           "diverging": [
            [
             0,
             "rgb(103,0,31)"
            ],
            [
             0.1,
             "rgb(178,24,43)"
            ],
            [
             0.2,
             "rgb(214,96,77)"
            ],
            [
             0.3,
             "rgb(244,165,130)"
            ],
            [
             0.4,
             "rgb(253,219,199)"
            ],
            [
             0.5,
             "rgb(247,247,247)"
            ],
            [
             0.6,
             "rgb(209,229,240)"
            ],
            [
             0.7,
             "rgb(146,197,222)"
            ],
            [
             0.8,
             "rgb(67,147,195)"
            ],
            [
             0.9,
             "rgb(33,102,172)"
            ],
            [
             1,
             "rgb(5,48,97)"
            ]
           ],
           "sequential": [
            [
             0,
             "#440154"
            ],
            [
             0.1111111111111111,
             "#482878"
            ],
            [
             0.2222222222222222,
             "#3e4989"
            ],
            [
             0.3333333333333333,
             "#31688e"
            ],
            [
             0.4444444444444444,
             "#26828e"
            ],
            [
             0.5555555555555556,
             "#1f9e89"
            ],
            [
             0.6666666666666666,
             "#35b779"
            ],
            [
             0.7777777777777778,
             "#6ece58"
            ],
            [
             0.8888888888888888,
             "#b5de2b"
            ],
            [
             1,
             "#fde725"
            ]
           ],
           "sequentialminus": [
            [
             0,
             "#440154"
            ],
            [
             0.1111111111111111,
             "#482878"
            ],
            [
             0.2222222222222222,
             "#3e4989"
            ],
            [
             0.3333333333333333,
             "#31688e"
            ],
            [
             0.4444444444444444,
             "#26828e"
            ],
            [
             0.5555555555555556,
             "#1f9e89"
            ],
            [
             0.6666666666666666,
             "#35b779"
            ],
            [
             0.7777777777777778,
             "#6ece58"
            ],
            [
             0.8888888888888888,
             "#b5de2b"
            ],
            [
             1,
             "#fde725"
            ]
           ]
          },
          "colorway": [
           "#1F77B4",
           "#FF7F0E",
           "#2CA02C",
           "#D62728",
           "#9467BD",
           "#8C564B",
           "#E377C2",
           "#7F7F7F",
           "#BCBD22",
           "#17BECF"
          ],
          "font": {
           "color": "rgb(36,36,36)"
          },
          "geo": {
           "bgcolor": "white",
           "lakecolor": "white",
           "landcolor": "white",
           "showlakes": true,
           "showland": true,
           "subunitcolor": "white"
          },
          "hoverlabel": {
           "align": "left"
          },
          "hovermode": "closest",
          "mapbox": {
           "style": "light"
          },
          "paper_bgcolor": "white",
          "plot_bgcolor": "white",
          "polar": {
           "angularaxis": {
            "gridcolor": "rgb(232,232,232)",
            "linecolor": "rgb(36,36,36)",
            "showgrid": false,
            "showline": true,
            "ticks": "outside"
           },
           "bgcolor": "white",
           "radialaxis": {
            "gridcolor": "rgb(232,232,232)",
            "linecolor": "rgb(36,36,36)",
            "showgrid": false,
            "showline": true,
            "ticks": "outside"
           }
          },
          "scene": {
           "xaxis": {
            "backgroundcolor": "white",
            "gridcolor": "rgb(232,232,232)",
            "gridwidth": 2,
            "linecolor": "rgb(36,36,36)",
            "showbackground": true,
            "showgrid": false,
            "showline": true,
            "ticks": "outside",
            "zeroline": false,
            "zerolinecolor": "rgb(36,36,36)"
           },
           "yaxis": {
            "backgroundcolor": "white",
            "gridcolor": "rgb(232,232,232)",
            "gridwidth": 2,
            "linecolor": "rgb(36,36,36)",
            "showbackground": true,
            "showgrid": false,
            "showline": true,
            "ticks": "outside",
            "zeroline": false,
            "zerolinecolor": "rgb(36,36,36)"
           },
           "zaxis": {
            "backgroundcolor": "white",
            "gridcolor": "rgb(232,232,232)",
            "gridwidth": 2,
            "linecolor": "rgb(36,36,36)",
            "showbackground": true,
            "showgrid": false,
            "showline": true,
            "ticks": "outside",
            "zeroline": false,
            "zerolinecolor": "rgb(36,36,36)"
           }
          },
          "shapedefaults": {
           "fillcolor": "black",
           "line": {
            "width": 0
           },
           "opacity": 0.3
          },
          "ternary": {
           "aaxis": {
            "gridcolor": "rgb(232,232,232)",
            "linecolor": "rgb(36,36,36)",
            "showgrid": false,
            "showline": true,
            "ticks": "outside"
           },
           "baxis": {
            "gridcolor": "rgb(232,232,232)",
            "linecolor": "rgb(36,36,36)",
            "showgrid": false,
            "showline": true,
            "ticks": "outside"
           },
           "bgcolor": "white",
           "caxis": {
            "gridcolor": "rgb(232,232,232)",
            "linecolor": "rgb(36,36,36)",
            "showgrid": false,
            "showline": true,
            "ticks": "outside"
           }
          },
          "title": {
           "x": 0.05
          },
          "xaxis": {
           "automargin": true,
           "gridcolor": "rgb(232,232,232)",
           "linecolor": "rgb(36,36,36)",
           "showgrid": false,
           "showline": true,
           "ticks": "outside",
           "title": {
            "standoff": 15
           },
           "zeroline": false,
           "zerolinecolor": "rgb(36,36,36)"
          },
          "yaxis": {
           "automargin": true,
           "gridcolor": "rgb(232,232,232)",
           "linecolor": "rgb(36,36,36)",
           "showgrid": false,
           "showline": true,
           "ticks": "outside",
           "title": {
            "standoff": 15
           },
           "zeroline": false,
           "zerolinecolor": "rgb(36,36,36)"
          }
         }
        },
        "title": {
         "font": {
          "color": "Black",
          "size": 22
         },
         "text": "<b>Topics over Time</b>",
         "x": 0.4,
         "xanchor": "center",
         "y": 0.95,
         "yanchor": "top"
        },
        "width": 1000,
        "xaxis": {
         "showgrid": true
        },
        "yaxis": {
         "showgrid": true,
         "title": {
          "text": "Frequency"
         }
        }
       }
      }
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 各 Topic 時間序列圖\n",
    "topics_over_time = topic_model.topics_over_time(\n",
    "    ws,     \n",
    "    timestamps,     \n",
    ")\n",
    "tot_fig = topic_model.visualize_topics_over_time(\n",
    "    topics_over_time, top_n_topics=12, width=1000\n",
    ")\n",
    "tot_fig"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.plotly.v1+json": {
       "config": {
        "plotlyServerURL": "https://plot.ly"
       },
       "data": [
        {
         "marker": {
          "color": "#D55E00"
         },
         "orientation": "h",
         "type": "bar",
         "x": [
          0.010036117168846038,
          0.010358506547658615,
          0.0106788410320816,
          0.010698859633264288,
          0.011671864319967307
         ],
         "xaxis": "x",
         "y": [
          "生技  ",
          "開發  ",
          "中心  ",
          "臨床試驗  ",
          "計畫  "
         ],
         "yaxis": "y"
        },
        {
         "marker": {
          "color": "#0072B2"
         },
         "orientation": "h",
         "type": "bar",
         "x": [
          0.012840369315768275,
          0.013344711270460653,
          0.013531355294615246,
          0.014271351261196953,
          0.0162898165763392
         ],
         "xaxis": "x2",
         "y": [
          "應用  ",
          "產業  ",
          "發展  ",
          "服務  ",
          "智慧  "
         ],
         "yaxis": "y2"
        },
        {
         "marker": {
          "color": "#CC79A7"
         },
         "orientation": "h",
         "type": "bar",
         "x": [
          0.01578994069289869,
          0.01583388449071344,
          0.015931341674847187,
          0.019298052269421336,
          0.024931485304576874
         ],
         "xaxis": "x3",
         "y": [
          "訊號  ",
          "實驗  ",
          "頻道  ",
          "行政  ",
          "中子  "
         ],
         "yaxis": "y3"
        },
        {
         "marker": {
          "color": "#E69F00"
         },
         "orientation": "h",
         "type": "bar",
         "x": [
          0.018245889255145812,
          0.018270356399692125,
          0.0183354611928508,
          0.023199971305239788,
          0.04340033768876724
         ],
         "xaxis": "x4",
         "y": [
          "食媒性  ",
          "食材  ",
          "食品安全  ",
          "食品產業  ",
          "食品  "
         ],
         "yaxis": "y4"
        },
        {
         "marker": {
          "color": "#56B4E9"
         },
         "orientation": "h",
         "type": "bar",
         "x": [
          0.016462123966053496,
          0.016819153912223883,
          0.016951842528449633,
          0.018055115167948405,
          0.020226475421989475
         ],
         "xaxis": "x5",
         "y": [
          "石化  ",
          "技術  ",
          "產業  ",
          "基礎  ",
          "超高畫質  "
         ],
         "yaxis": "y5"
        },
        {
         "marker": {
          "color": "#009E73"
         },
         "orientation": "h",
         "type": "bar",
         "x": [
          0.019213738809956207,
          0.019644641014467952,
          0.022262091699000144,
          0.022617764817073394,
          0.044360590702848667
         ],
         "xaxis": "x6",
         "y": [
          "用水  ",
          "氣候變遷  ",
          "水資源  ",
          "混凝土  ",
          "地下水  "
         ],
         "yaxis": "y6"
        },
        {
         "marker": {
          "color": "#F0E442"
         },
         "orientation": "h",
         "type": "bar",
         "x": [
          0.025989495319065685,
          0.026155895875823284,
          0.02724730513272366,
          0.02849321310375216,
          0.030703461179395986
         ],
         "xaxis": "x7",
         "y": [
          "儀器  ",
          "光束線  ",
          "設施  ",
          "光子源  ",
          "光源  "
         ],
         "yaxis": "y7"
        },
        {
         "marker": {
          "color": "#D55E00"
         },
         "orientation": "h",
         "type": "bar",
         "x": [
          0.016178798001916274,
          0.019996998644316036,
          0.02117393601397003,
          0.022820429423951127,
          0.027014113121812827
         ],
         "xaxis": "x8",
         "y": [
          "學術  ",
          "領域  ",
          "社會創新  ",
          "社會科學  ",
          "人文  "
         ],
         "yaxis": "y8"
        },
        {
         "marker": {
          "color": "#0072B2"
         },
         "orientation": "h",
         "type": "bar",
         "x": [
          0.016823737053654045,
          0.01705607984260705,
          0.01774483437408217,
          0.01819365272349642,
          0.032203601246784626
         ],
         "xaxis": "x9",
         "y": [
          "技術  ",
          "系統  ",
          "大型  ",
          "模組  ",
          "車輛  "
         ],
         "yaxis": "y9"
        },
        {
         "marker": {
          "color": "#CC79A7"
         },
         "orientation": "h",
         "type": "bar",
         "x": [
          0.017640395275580457,
          0.01975905514443746,
          0.02036147094608936,
          0.021217334704581526,
          0.02204602573042941
         ],
         "xaxis": "x10",
         "y": [
          "活動斷層  ",
          "耐震評估  ",
          "山崩潛勢  ",
          "山崩  ",
          "研發成果  "
         ],
         "yaxis": "y10"
        },
        {
         "marker": {
          "color": "#E69F00"
         },
         "orientation": "h",
         "type": "bar",
         "x": [
          0.0328218556090127,
          0.03295156206050777,
          0.0370506974653674,
          0.03761736203756081,
          0.0530372794541444
         ],
         "xaxis": "x11",
         "y": [
          "處置  ",
          "勞動  ",
          "子項  ",
          "廢棄物  ",
          "研究  "
         ],
         "yaxis": "y11"
        },
        {
         "marker": {
          "color": "#56B4E9"
         },
         "orientation": "h",
         "type": "bar",
         "x": [
          0.024299717862355803,
          0.02456976894408899,
          0.025888136519192917,
          0.04252718243236,
          0.07990365608402077
         ],
         "xaxis": "x12",
         "y": [
          "海象  ",
          "探測  ",
          "海域  ",
          "海洋科技  ",
          "海洋  "
         ],
         "yaxis": "y12"
        }
       ],
       "layout": {
        "annotations": [
         {
          "font": {
           "size": 16
          },
          "showarrow": false,
          "text": "Topic 0",
          "x": 0.0875,
          "xanchor": "center",
          "xref": "paper",
          "y": 1,
          "yanchor": "bottom",
          "yref": "paper"
         },
         {
          "font": {
           "size": 16
          },
          "showarrow": false,
          "text": "Topic 1",
          "x": 0.36250000000000004,
          "xanchor": "center",
          "xref": "paper",
          "y": 1,
          "yanchor": "bottom",
          "yref": "paper"
         },
         {
          "font": {
           "size": 16
          },
          "showarrow": false,
          "text": "Topic 2",
          "x": 0.6375000000000001,
          "xanchor": "center",
          "xref": "paper",
          "y": 1,
          "yanchor": "bottom",
          "yref": "paper"
         },
         {
          "font": {
           "size": 16
          },
          "showarrow": false,
          "text": "Topic 3",
          "x": 0.9125,
          "xanchor": "center",
          "xref": "paper",
          "y": 1,
          "yanchor": "bottom",
          "yref": "paper"
         },
         {
          "font": {
           "size": 16
          },
          "showarrow": false,
          "text": "Topic 4",
          "x": 0.0875,
          "xanchor": "center",
          "xref": "paper",
          "y": 0.6222222222222222,
          "yanchor": "bottom",
          "yref": "paper"
         },
         {
          "font": {
           "size": 16
          },
          "showarrow": false,
          "text": "Topic 5",
          "x": 0.36250000000000004,
          "xanchor": "center",
          "xref": "paper",
          "y": 0.6222222222222222,
          "yanchor": "bottom",
          "yref": "paper"
         },
         {
          "font": {
           "size": 16
          },
          "showarrow": false,
          "text": "Topic 6",
          "x": 0.6375000000000001,
          "xanchor": "center",
          "xref": "paper",
          "y": 0.6222222222222222,
          "yanchor": "bottom",
          "yref": "paper"
         },
         {
          "font": {
           "size": 16
          },
          "showarrow": false,
          "text": "Topic 7",
          "x": 0.9125,
          "xanchor": "center",
          "xref": "paper",
          "y": 0.6222222222222222,
          "yanchor": "bottom",
          "yref": "paper"
         },
         {
          "font": {
           "size": 16
          },
          "showarrow": false,
          "text": "Topic 8",
          "x": 0.0875,
          "xanchor": "center",
          "xref": "paper",
          "y": 0.24444444444444446,
          "yanchor": "bottom",
          "yref": "paper"
         },
         {
          "font": {
           "size": 16
          },
          "showarrow": false,
          "text": "Topic 9",
          "x": 0.36250000000000004,
          "xanchor": "center",
          "xref": "paper",
          "y": 0.24444444444444446,
          "yanchor": "bottom",
          "yref": "paper"
         },
         {
          "font": {
           "size": 16
          },
          "showarrow": false,
          "text": "Topic 10",
          "x": 0.6375000000000001,
          "xanchor": "center",
          "xref": "paper",
          "y": 0.24444444444444446,
          "yanchor": "bottom",
          "yref": "paper"
         },
         {
          "font": {
           "size": 16
          },
          "showarrow": false,
          "text": "Topic 11",
          "x": 0.9125,
          "xanchor": "center",
          "xref": "paper",
          "y": 0.24444444444444446,
          "yanchor": "bottom",
          "yref": "paper"
         }
        ],
        "height": 750,
        "hoverlabel": {
         "bgcolor": "white",
         "font": {
          "family": "Rockwell",
          "size": 16
         }
        },
        "showlegend": false,
        "template": {
         "data": {
          "bar": [
           {
            "error_x": {
             "color": "#2a3f5f"
            },
            "error_y": {
             "color": "#2a3f5f"
            },
            "marker": {
             "line": {
              "color": "white",
              "width": 0.5
             },
             "pattern": {
              "fillmode": "overlay",
              "size": 10,
              "solidity": 0.2
             }
            },
            "type": "bar"
           }
          ],
          "barpolar": [
           {
            "marker": {
             "line": {
              "color": "white",
              "width": 0.5
             },
             "pattern": {
              "fillmode": "overlay",
              "size": 10,
              "solidity": 0.2
             }
            },
            "type": "barpolar"
           }
          ],
          "carpet": [
           {
            "aaxis": {
             "endlinecolor": "#2a3f5f",
             "gridcolor": "#C8D4E3",
             "linecolor": "#C8D4E3",
             "minorgridcolor": "#C8D4E3",
             "startlinecolor": "#2a3f5f"
            },
            "baxis": {
             "endlinecolor": "#2a3f5f",
             "gridcolor": "#C8D4E3",
             "linecolor": "#C8D4E3",
             "minorgridcolor": "#C8D4E3",
             "startlinecolor": "#2a3f5f"
            },
            "type": "carpet"
           }
          ],
          "choropleth": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "type": "choropleth"
           }
          ],
          "contour": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "contour"
           }
          ],
          "contourcarpet": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "type": "contourcarpet"
           }
          ],
          "heatmap": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "heatmap"
           }
          ],
          "heatmapgl": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "heatmapgl"
           }
          ],
          "histogram": [
           {
            "marker": {
             "pattern": {
              "fillmode": "overlay",
              "size": 10,
              "solidity": 0.2
             }
            },
            "type": "histogram"
           }
          ],
          "histogram2d": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "histogram2d"
           }
          ],
          "histogram2dcontour": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "histogram2dcontour"
           }
          ],
          "mesh3d": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "type": "mesh3d"
           }
          ],
          "parcoords": [
           {
            "line": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "parcoords"
           }
          ],
          "pie": [
           {
            "automargin": true,
            "type": "pie"
           }
          ],
          "scatter": [
           {
            "fillpattern": {
             "fillmode": "overlay",
             "size": 10,
             "solidity": 0.2
            },
            "type": "scatter"
           }
          ],
          "scatter3d": [
           {
            "line": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatter3d"
           }
          ],
          "scattercarpet": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattercarpet"
           }
          ],
          "scattergeo": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattergeo"
           }
          ],
          "scattergl": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattergl"
           }
          ],
          "scattermapbox": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattermapbox"
           }
          ],
          "scatterpolar": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatterpolar"
           }
          ],
          "scatterpolargl": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatterpolargl"
           }
          ],
          "scatterternary": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatterternary"
           }
          ],
          "surface": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "surface"
           }
          ],
          "table": [
           {
            "cells": {
             "fill": {
              "color": "#EBF0F8"
             },
             "line": {
              "color": "white"
             }
            },
            "header": {
             "fill": {
              "color": "#C8D4E3"
             },
             "line": {
              "color": "white"
             }
            },
            "type": "table"
           }
          ]
         },
         "layout": {
          "annotationdefaults": {
           "arrowcolor": "#2a3f5f",
           "arrowhead": 0,
           "arrowwidth": 1
          },
          "autotypenumbers": "strict",
          "coloraxis": {
           "colorbar": {
            "outlinewidth": 0,
            "ticks": ""
           }
          },
          "colorscale": {
           "diverging": [
            [
             0,
             "#8e0152"
            ],
            [
             0.1,
             "#c51b7d"
            ],
            [
             0.2,
             "#de77ae"
            ],
            [
             0.3,
             "#f1b6da"
            ],
            [
             0.4,
             "#fde0ef"
            ],
            [
             0.5,
             "#f7f7f7"
            ],
            [
             0.6,
             "#e6f5d0"
            ],
            [
             0.7,
             "#b8e186"
            ],
            [
             0.8,
             "#7fbc41"
            ],
            [
             0.9,
             "#4d9221"
            ],
            [
             1,
             "#276419"
            ]
           ],
           "sequential": [
            [
             0,
             "#0d0887"
            ],
            [
             0.1111111111111111,
             "#46039f"
            ],
            [
             0.2222222222222222,
             "#7201a8"
            ],
            [
             0.3333333333333333,
             "#9c179e"
            ],
            [
             0.4444444444444444,
             "#bd3786"
            ],
            [
             0.5555555555555556,
             "#d8576b"
            ],
            [
             0.6666666666666666,
             "#ed7953"
            ],
            [
             0.7777777777777778,
             "#fb9f3a"
            ],
            [
             0.8888888888888888,
             "#fdca26"
            ],
            [
             1,
             "#f0f921"
            ]
           ],
           "sequentialminus": [
            [
             0,
             "#0d0887"
            ],
            [
             0.1111111111111111,
             "#46039f"
            ],
            [
             0.2222222222222222,
             "#7201a8"
            ],
            [
             0.3333333333333333,
             "#9c179e"
            ],
            [
             0.4444444444444444,
             "#bd3786"
            ],
            [
             0.5555555555555556,
             "#d8576b"
            ],
            [
             0.6666666666666666,
             "#ed7953"
            ],
            [
             0.7777777777777778,
             "#fb9f3a"
            ],
            [
             0.8888888888888888,
             "#fdca26"
            ],
            [
             1,
             "#f0f921"
            ]
           ]
          },
          "colorway": [
           "#636efa",
           "#EF553B",
           "#00cc96",
           "#ab63fa",
           "#FFA15A",
           "#19d3f3",
           "#FF6692",
           "#B6E880",
           "#FF97FF",
           "#FECB52"
          ],
          "font": {
           "color": "#2a3f5f"
          },
          "geo": {
           "bgcolor": "white",
           "lakecolor": "white",
           "landcolor": "white",
           "showlakes": true,
           "showland": true,
           "subunitcolor": "#C8D4E3"
          },
          "hoverlabel": {
           "align": "left"
          },
          "hovermode": "closest",
          "mapbox": {
           "style": "light"
          },
          "paper_bgcolor": "white",
          "plot_bgcolor": "white",
          "polar": {
           "angularaxis": {
            "gridcolor": "#EBF0F8",
            "linecolor": "#EBF0F8",
            "ticks": ""
           },
           "bgcolor": "white",
           "radialaxis": {
            "gridcolor": "#EBF0F8",
            "linecolor": "#EBF0F8",
            "ticks": ""
           }
          },
          "scene": {
           "xaxis": {
            "backgroundcolor": "white",
            "gridcolor": "#DFE8F3",
            "gridwidth": 2,
            "linecolor": "#EBF0F8",
            "showbackground": true,
            "ticks": "",
            "zerolinecolor": "#EBF0F8"
           },
           "yaxis": {
            "backgroundcolor": "white",
            "gridcolor": "#DFE8F3",
            "gridwidth": 2,
            "linecolor": "#EBF0F8",
            "showbackground": true,
            "ticks": "",
            "zerolinecolor": "#EBF0F8"
           },
           "zaxis": {
            "backgroundcolor": "white",
            "gridcolor": "#DFE8F3",
            "gridwidth": 2,
            "linecolor": "#EBF0F8",
            "showbackground": true,
            "ticks": "",
            "zerolinecolor": "#EBF0F8"
           }
          },
          "shapedefaults": {
           "line": {
            "color": "#2a3f5f"
           }
          },
          "ternary": {
           "aaxis": {
            "gridcolor": "#DFE8F3",
            "linecolor": "#A2B1C6",
            "ticks": ""
           },
           "baxis": {
            "gridcolor": "#DFE8F3",
            "linecolor": "#A2B1C6",
            "ticks": ""
           },
           "bgcolor": "white",
           "caxis": {
            "gridcolor": "#DFE8F3",
            "linecolor": "#A2B1C6",
            "ticks": ""
           }
          },
          "title": {
           "x": 0.05
          },
          "xaxis": {
           "automargin": true,
           "gridcolor": "#EBF0F8",
           "linecolor": "#EBF0F8",
           "ticks": "",
           "title": {
            "standoff": 15
           },
           "zerolinecolor": "#EBF0F8",
           "zerolinewidth": 2
          },
          "yaxis": {
           "automargin": true,
           "gridcolor": "#EBF0F8",
           "linecolor": "#EBF0F8",
           "ticks": "",
           "title": {
            "standoff": 15
           },
           "zerolinecolor": "#EBF0F8",
           "zerolinewidth": 2
          }
         }
        },
        "title": {
         "font": {
          "color": "Black",
          "size": 22
         },
         "text": "Topic Word Scores",
         "x": 0.5,
         "xanchor": "center",
         "yanchor": "top"
        },
        "width": 920,
        "xaxis": {
         "anchor": "y",
         "domain": [
          0,
          0.175
         ],
         "showgrid": true
        },
        "xaxis10": {
         "anchor": "y10",
         "domain": [
          0.275,
          0.45
         ],
         "showgrid": true
        },
        "xaxis11": {
         "anchor": "y11",
         "domain": [
          0.55,
          0.7250000000000001
         ],
         "showgrid": true
        },
        "xaxis12": {
         "anchor": "y12",
         "domain": [
          0.825,
          1
         ],
         "showgrid": true
        },
        "xaxis2": {
         "anchor": "y2",
         "domain": [
          0.275,
          0.45
         ],
         "showgrid": true
        },
        "xaxis3": {
         "anchor": "y3",
         "domain": [
          0.55,
          0.7250000000000001
         ],
         "showgrid": true
        },
        "xaxis4": {
         "anchor": "y4",
         "domain": [
          0.825,
          1
         ],
         "showgrid": true
        },
        "xaxis5": {
         "anchor": "y5",
         "domain": [
          0,
          0.175
         ],
         "showgrid": true
        },
        "xaxis6": {
         "anchor": "y6",
         "domain": [
          0.275,
          0.45
         ],
         "showgrid": true
        },
        "xaxis7": {
         "anchor": "y7",
         "domain": [
          0.55,
          0.7250000000000001
         ],
         "showgrid": true
        },
        "xaxis8": {
         "anchor": "y8",
         "domain": [
          0.825,
          1
         ],
         "showgrid": true
        },
        "xaxis9": {
         "anchor": "y9",
         "domain": [
          0,
          0.175
         ],
         "showgrid": true
        },
        "yaxis": {
         "anchor": "x",
         "domain": [
          0.7555555555555555,
          1
         ],
         "showgrid": true
        },
        "yaxis10": {
         "anchor": "x10",
         "domain": [
          0,
          0.24444444444444446
         ],
         "showgrid": true
        },
        "yaxis11": {
         "anchor": "x11",
         "domain": [
          0,
          0.24444444444444446
         ],
         "showgrid": true
        },
        "yaxis12": {
         "anchor": "x12",
         "domain": [
          0,
          0.24444444444444446
         ],
         "showgrid": true
        },
        "yaxis2": {
         "anchor": "x2",
         "domain": [
          0.7555555555555555,
          1
         ],
         "showgrid": true
        },
        "yaxis3": {
         "anchor": "x3",
         "domain": [
          0.7555555555555555,
          1
         ],
         "showgrid": true
        },
        "yaxis4": {
         "anchor": "x4",
         "domain": [
          0.7555555555555555,
          1
         ],
         "showgrid": true
        },
        "yaxis5": {
         "anchor": "x5",
         "domain": [
          0.37777777777777777,
          0.6222222222222222
         ],
         "showgrid": true
        },
        "yaxis6": {
         "anchor": "x6",
         "domain": [
          0.37777777777777777,
          0.6222222222222222
         ],
         "showgrid": true
        },
        "yaxis7": {
         "anchor": "x7",
         "domain": [
          0.37777777777777777,
          0.6222222222222222
         ],
         "showgrid": true
        },
        "yaxis8": {
         "anchor": "x8",
         "domain": [
          0.37777777777777777,
          0.6222222222222222
         ],
         "showgrid": true
        },
        "yaxis9": {
         "anchor": "x9",
         "domain": [
          0,
          0.24444444444444446
         ],
         "showgrid": true
        }
       }
      }
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 各 Topic TF-IDF 關鍵字直方圖\n",
    "bar_fig = topic_model.visualize_barchart(\n",
    "    top_n_topics=12,\n",
    "    width=230,\n",
    ")\n",
    "bar_fig"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.plotly.v1+json": {
       "config": {
        "plotlyServerURL": "https://plot.ly"
       },
       "data": [
        {
         "customdata": [
          [
           0,
           "計畫 | 臨床試驗 | 中心 | 開發 | 生技",
           330
          ],
          [
           1,
           "智慧 | 服務 | 發展 | 產業 | 應用",
           271
          ],
          [
           2,
           "中子 | 行政 | 頻道 | 實驗 | 訊號",
           155
          ],
          [
           3,
           "食品 | 食品產業 | 食品安全 | 食材 | 食媒性",
           89
          ],
          [
           4,
           "超高畫質 | 基礎 | 產業 | 技術 | 石化",
           79
          ],
          [
           5,
           "地下水 | 混凝土 | 水資源 | 氣候變遷 | 用水",
           69
          ],
          [
           6,
           "光源 | 光子源 | 設施 | 光束線 | 儀器",
           59
          ],
          [
           7,
           "人文 | 社會科學 | 社會創新 | 領域 | 學術",
           49
          ],
          [
           8,
           "車輛 | 模組 | 大型 | 系統 | 技術",
           48
          ],
          [
           9,
           "研發成果 | 山崩 | 山崩潛勢 | 耐震評估 | 活動斷層",
           44
          ]
         ],
         "hovertemplate": "<b>Topic %{customdata[0]}</b><br>%{customdata[1]}<br>Size: %{customdata[2]}",
         "legendgroup": "",
         "marker": {
          "color": "#B0BEC5",
          "line": {
           "color": "DarkSlateGrey",
           "width": 2
          },
          "size": [
           330,
           271,
           155,
           89,
           79,
           69,
           59,
           49,
           48,
           44
          ],
          "sizemode": "area",
          "sizeref": 0.20625,
          "symbol": "circle"
         },
         "mode": "markers",
         "name": "",
         "orientation": "v",
         "showlegend": false,
         "type": "scatter",
         "x": [
          17.96601104736328,
          -0.20142881572246552,
          17.805370330810547,
          18.284164428710938,
          -0.6609519124031067,
          -1.7333014011383057,
          -0.5467479825019836,
          18.24008560180664,
          -1.2730786800384521,
          -1.2586079835891724
         ],
         "xaxis": "x",
         "y": [
          12.663885116577148,
          14.88134479522705,
          11.765763282775879,
          13.034785270690918,
          14.63888931274414,
          14.921974182128906,
          14.147262573242188,
          12.08366870880127,
          15.501675605773926,
          15.041316032409668
         ],
         "yaxis": "y"
        }
       ],
       "layout": {
        "annotations": [
         {
          "showarrow": false,
          "text": "D1",
          "x": -1.9932966113090516,
          "y": 13.913912868499756,
          "yshift": 10
         },
         {
          "showarrow": false,
          "text": "D2",
          "x": 9.516746240854262,
          "xshift": 10,
          "y": 17.826926946640015
         }
        ],
        "height": 650,
        "hoverlabel": {
         "bgcolor": "white",
         "font": {
          "family": "Rockwell",
          "size": 16
         }
        },
        "legend": {
         "itemsizing": "constant",
         "tracegroupgap": 0
        },
        "margin": {
         "t": 60
        },
        "shapes": [
         {
          "line": {
           "color": "#CFD8DC",
           "width": 2
          },
          "type": "line",
          "x0": 9.516746240854262,
          "x1": 9.516746240854262,
          "y0": 10.000898790359496,
          "y1": 17.826926946640015
         },
         {
          "line": {
           "color": "#9E9E9E",
           "width": 2
          },
          "type": "line",
          "x0": -1.9932966113090516,
          "x1": 21.026789093017577,
          "y0": 13.913912868499756,
          "y1": 13.913912868499756
         }
        ],
        "sliders": [
         {
          "active": 0,
          "pad": {
           "t": 50
          },
          "steps": [
           {
            "args": [
             {
              "marker.color": [
               [
                "red",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5"
               ]
              ]
             }
            ],
            "label": "Topic 0",
            "method": "update"
           },
           {
            "args": [
             {
              "marker.color": [
               [
                "#B0BEC5",
                "red",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5"
               ]
              ]
             }
            ],
            "label": "Topic 1",
            "method": "update"
           },
           {
            "args": [
             {
              "marker.color": [
               [
                "#B0BEC5",
                "#B0BEC5",
                "red",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5"
               ]
              ]
             }
            ],
            "label": "Topic 2",
            "method": "update"
           },
           {
            "args": [
             {
              "marker.color": [
               [
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "red",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5"
               ]
              ]
             }
            ],
            "label": "Topic 3",
            "method": "update"
           },
           {
            "args": [
             {
              "marker.color": [
               [
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "red",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5"
               ]
              ]
             }
            ],
            "label": "Topic 4",
            "method": "update"
           },
           {
            "args": [
             {
              "marker.color": [
               [
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "red",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5"
               ]
              ]
             }
            ],
            "label": "Topic 5",
            "method": "update"
           },
           {
            "args": [
             {
              "marker.color": [
               [
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "red",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5"
               ]
              ]
             }
            ],
            "label": "Topic 6",
            "method": "update"
           },
           {
            "args": [
             {
              "marker.color": [
               [
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "red",
                "#B0BEC5",
                "#B0BEC5"
               ]
              ]
             }
            ],
            "label": "Topic 7",
            "method": "update"
           },
           {
            "args": [
             {
              "marker.color": [
               [
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "red",
                "#B0BEC5"
               ]
              ]
             }
            ],
            "label": "Topic 8",
            "method": "update"
           },
           {
            "args": [
             {
              "marker.color": [
               [
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "#B0BEC5",
                "red"
               ]
              ]
             }
            ],
            "label": "Topic 9",
            "method": "update"
           }
          ]
         }
        ],
        "template": {
         "data": {
          "bar": [
           {
            "error_x": {
             "color": "rgb(36,36,36)"
            },
            "error_y": {
             "color": "rgb(36,36,36)"
            },
            "marker": {
             "line": {
              "color": "white",
              "width": 0.5
             },
             "pattern": {
              "fillmode": "overlay",
              "size": 10,
              "solidity": 0.2
             }
            },
            "type": "bar"
           }
          ],
          "barpolar": [
           {
            "marker": {
             "line": {
              "color": "white",
              "width": 0.5
             },
             "pattern": {
              "fillmode": "overlay",
              "size": 10,
              "solidity": 0.2
             }
            },
            "type": "barpolar"
           }
          ],
          "carpet": [
           {
            "aaxis": {
             "endlinecolor": "rgb(36,36,36)",
             "gridcolor": "white",
             "linecolor": "white",
             "minorgridcolor": "white",
             "startlinecolor": "rgb(36,36,36)"
            },
            "baxis": {
             "endlinecolor": "rgb(36,36,36)",
             "gridcolor": "white",
             "linecolor": "white",
             "minorgridcolor": "white",
             "startlinecolor": "rgb(36,36,36)"
            },
            "type": "carpet"
           }
          ],
          "choropleth": [
           {
            "colorbar": {
             "outlinewidth": 1,
             "tickcolor": "rgb(36,36,36)",
             "ticks": "outside"
            },
            "type": "choropleth"
           }
          ],
          "contour": [
           {
            "colorbar": {
             "outlinewidth": 1,
             "tickcolor": "rgb(36,36,36)",
             "ticks": "outside"
            },
            "colorscale": [
             [
              0,
              "#440154"
             ],
             [
              0.1111111111111111,
              "#482878"
             ],
             [
              0.2222222222222222,
              "#3e4989"
             ],
             [
              0.3333333333333333,
              "#31688e"
             ],
             [
              0.4444444444444444,
              "#26828e"
             ],
             [
              0.5555555555555556,
              "#1f9e89"
             ],
             [
              0.6666666666666666,
              "#35b779"
             ],
             [
              0.7777777777777778,
              "#6ece58"
             ],
             [
              0.8888888888888888,
              "#b5de2b"
             ],
             [
              1,
              "#fde725"
             ]
            ],
            "type": "contour"
           }
          ],
          "contourcarpet": [
           {
            "colorbar": {
             "outlinewidth": 1,
             "tickcolor": "rgb(36,36,36)",
             "ticks": "outside"
            },
            "type": "contourcarpet"
           }
          ],
          "heatmap": [
           {
            "colorbar": {
             "outlinewidth": 1,
             "tickcolor": "rgb(36,36,36)",
             "ticks": "outside"
            },
            "colorscale": [
             [
              0,
              "#440154"
             ],
             [
              0.1111111111111111,
              "#482878"
             ],
             [
              0.2222222222222222,
              "#3e4989"
             ],
             [
              0.3333333333333333,
              "#31688e"
             ],
             [
              0.4444444444444444,
              "#26828e"
             ],
             [
              0.5555555555555556,
              "#1f9e89"
             ],
             [
              0.6666666666666666,
              "#35b779"
             ],
             [
              0.7777777777777778,
              "#6ece58"
             ],
             [
              0.8888888888888888,
              "#b5de2b"
             ],
             [
              1,
              "#fde725"
             ]
            ],
            "type": "heatmap"
           }
          ],
          "heatmapgl": [
           {
            "colorbar": {
             "outlinewidth": 1,
             "tickcolor": "rgb(36,36,36)",
             "ticks": "outside"
            },
            "colorscale": [
             [
              0,
              "#440154"
             ],
             [
              0.1111111111111111,
              "#482878"
             ],
             [
              0.2222222222222222,
              "#3e4989"
             ],
             [
              0.3333333333333333,
              "#31688e"
             ],
             [
              0.4444444444444444,
              "#26828e"
             ],
             [
              0.5555555555555556,
              "#1f9e89"
             ],
             [
              0.6666666666666666,
              "#35b779"
             ],
             [
              0.7777777777777778,
              "#6ece58"
             ],
             [
              0.8888888888888888,
              "#b5de2b"
             ],
             [
              1,
              "#fde725"
             ]
            ],
            "type": "heatmapgl"
           }
          ],
          "histogram": [
           {
            "marker": {
             "line": {
              "color": "white",
              "width": 0.6
             }
            },
            "type": "histogram"
           }
          ],
          "histogram2d": [
           {
            "colorbar": {
             "outlinewidth": 1,
             "tickcolor": "rgb(36,36,36)",
             "ticks": "outside"
            },
            "colorscale": [
             [
              0,
              "#440154"
             ],
             [
              0.1111111111111111,
              "#482878"
             ],
             [
              0.2222222222222222,
              "#3e4989"
             ],
             [
              0.3333333333333333,
              "#31688e"
             ],
             [
              0.4444444444444444,
              "#26828e"
             ],
             [
              0.5555555555555556,
              "#1f9e89"
             ],
             [
              0.6666666666666666,
              "#35b779"
             ],
             [
              0.7777777777777778,
              "#6ece58"
             ],
             [
              0.8888888888888888,
              "#b5de2b"
             ],
             [
              1,
              "#fde725"
             ]
            ],
            "type": "histogram2d"
           }
          ],
          "histogram2dcontour": [
           {
            "colorbar": {
             "outlinewidth": 1,
             "tickcolor": "rgb(36,36,36)",
             "ticks": "outside"
            },
            "colorscale": [
             [
              0,
              "#440154"
             ],
             [
              0.1111111111111111,
              "#482878"
             ],
             [
              0.2222222222222222,
              "#3e4989"
             ],
             [
              0.3333333333333333,
              "#31688e"
             ],
             [
              0.4444444444444444,
              "#26828e"
             ],
             [
              0.5555555555555556,
              "#1f9e89"
             ],
             [
              0.6666666666666666,
              "#35b779"
             ],
             [
              0.7777777777777778,
              "#6ece58"
             ],
             [
              0.8888888888888888,
              "#b5de2b"
             ],
             [
              1,
              "#fde725"
             ]
            ],
            "type": "histogram2dcontour"
           }
          ],
          "mesh3d": [
           {
            "colorbar": {
             "outlinewidth": 1,
             "tickcolor": "rgb(36,36,36)",
             "ticks": "outside"
            },
            "type": "mesh3d"
           }
          ],
          "parcoords": [
           {
            "line": {
             "colorbar": {
              "outlinewidth": 1,
              "tickcolor": "rgb(36,36,36)",
              "ticks": "outside"
             }
            },
            "type": "parcoords"
           }
          ],
          "pie": [
           {
            "automargin": true,
            "type": "pie"
           }
          ],
          "scatter": [
           {
            "fillpattern": {
             "fillmode": "overlay",
             "size": 10,
             "solidity": 0.2
            },
            "type": "scatter"
           }
          ],
          "scatter3d": [
           {
            "line": {
             "colorbar": {
              "outlinewidth": 1,
              "tickcolor": "rgb(36,36,36)",
              "ticks": "outside"
             }
            },
            "marker": {
             "colorbar": {
              "outlinewidth": 1,
              "tickcolor": "rgb(36,36,36)",
              "ticks": "outside"
             }
            },
            "type": "scatter3d"
           }
          ],
          "scattercarpet": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 1,
              "tickcolor": "rgb(36,36,36)",
              "ticks": "outside"
             }
            },
            "type": "scattercarpet"
           }
          ],
          "scattergeo": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 1,
              "tickcolor": "rgb(36,36,36)",
              "ticks": "outside"
             }
            },
            "type": "scattergeo"
           }
          ],
          "scattergl": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 1,
              "tickcolor": "rgb(36,36,36)",
              "ticks": "outside"
             }
            },
            "type": "scattergl"
           }
          ],
          "scattermapbox": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 1,
              "tickcolor": "rgb(36,36,36)",
              "ticks": "outside"
             }
            },
            "type": "scattermapbox"
           }
          ],
          "scatterpolar": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 1,
              "tickcolor": "rgb(36,36,36)",
              "ticks": "outside"
             }
            },
            "type": "scatterpolar"
           }
          ],
          "scatterpolargl": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 1,
              "tickcolor": "rgb(36,36,36)",
              "ticks": "outside"
             }
            },
            "type": "scatterpolargl"
           }
          ],
          "scatterternary": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 1,
              "tickcolor": "rgb(36,36,36)",
              "ticks": "outside"
             }
            },
            "type": "scatterternary"
           }
          ],
          "surface": [
           {
            "colorbar": {
             "outlinewidth": 1,
             "tickcolor": "rgb(36,36,36)",
             "ticks": "outside"
            },
            "colorscale": [
             [
              0,
              "#440154"
             ],
             [
              0.1111111111111111,
              "#482878"
             ],
             [
              0.2222222222222222,
              "#3e4989"
             ],
             [
              0.3333333333333333,
              "#31688e"
             ],
             [
              0.4444444444444444,
              "#26828e"
             ],
             [
              0.5555555555555556,
              "#1f9e89"
             ],
             [
              0.6666666666666666,
              "#35b779"
             ],
             [
              0.7777777777777778,
              "#6ece58"
             ],
             [
              0.8888888888888888,
              "#b5de2b"
             ],
             [
              1,
              "#fde725"
             ]
            ],
            "type": "surface"
           }
          ],
          "table": [
           {
            "cells": {
             "fill": {
              "color": "rgb(237,237,237)"
             },
             "line": {
              "color": "white"
             }
            },
            "header": {
             "fill": {
              "color": "rgb(217,217,217)"
             },
             "line": {
              "color": "white"
             }
            },
            "type": "table"
           }
          ]
         },
         "layout": {
          "annotationdefaults": {
           "arrowhead": 0,
           "arrowwidth": 1
          },
          "autotypenumbers": "strict",
          "coloraxis": {
           "colorbar": {
            "outlinewidth": 1,
            "tickcolor": "rgb(36,36,36)",
            "ticks": "outside"
           }
          },
          "colorscale": {
           "diverging": [
            [
             0,
             "rgb(103,0,31)"
            ],
            [
             0.1,
             "rgb(178,24,43)"
            ],
            [
             0.2,
             "rgb(214,96,77)"
            ],
            [
             0.3,
             "rgb(244,165,130)"
            ],
            [
             0.4,
             "rgb(253,219,199)"
            ],
            [
             0.5,
             "rgb(247,247,247)"
            ],
            [
             0.6,
             "rgb(209,229,240)"
            ],
            [
             0.7,
             "rgb(146,197,222)"
            ],
            [
             0.8,
             "rgb(67,147,195)"
            ],
            [
             0.9,
             "rgb(33,102,172)"
            ],
            [
             1,
             "rgb(5,48,97)"
            ]
           ],
           "sequential": [
            [
             0,
             "#440154"
            ],
            [
             0.1111111111111111,
             "#482878"
            ],
            [
             0.2222222222222222,
             "#3e4989"
            ],
            [
             0.3333333333333333,
             "#31688e"
            ],
            [
             0.4444444444444444,
             "#26828e"
            ],
            [
             0.5555555555555556,
             "#1f9e89"
            ],
            [
             0.6666666666666666,
             "#35b779"
            ],
            [
             0.7777777777777778,
             "#6ece58"
            ],
            [
             0.8888888888888888,
             "#b5de2b"
            ],
            [
             1,
             "#fde725"
            ]
           ],
           "sequentialminus": [
            [
             0,
             "#440154"
            ],
            [
             0.1111111111111111,
             "#482878"
            ],
            [
             0.2222222222222222,
             "#3e4989"
            ],
            [
             0.3333333333333333,
             "#31688e"
            ],
            [
             0.4444444444444444,
             "#26828e"
            ],
            [
             0.5555555555555556,
             "#1f9e89"
            ],
            [
             0.6666666666666666,
             "#35b779"
            ],
            [
             0.7777777777777778,
             "#6ece58"
            ],
            [
             0.8888888888888888,
             "#b5de2b"
            ],
            [
             1,
             "#fde725"
            ]
           ]
          },
          "colorway": [
           "#1F77B4",
           "#FF7F0E",
           "#2CA02C",
           "#D62728",
           "#9467BD",
           "#8C564B",
           "#E377C2",
           "#7F7F7F",
           "#BCBD22",
           "#17BECF"
          ],
          "font": {
           "color": "rgb(36,36,36)"
          },
          "geo": {
           "bgcolor": "white",
           "lakecolor": "white",
           "landcolor": "white",
           "showlakes": true,
           "showland": true,
           "subunitcolor": "white"
          },
          "hoverlabel": {
           "align": "left"
          },
          "hovermode": "closest",
          "mapbox": {
           "style": "light"
          },
          "paper_bgcolor": "white",
          "plot_bgcolor": "white",
          "polar": {
           "angularaxis": {
            "gridcolor": "rgb(232,232,232)",
            "linecolor": "rgb(36,36,36)",
            "showgrid": false,
            "showline": true,
            "ticks": "outside"
           },
           "bgcolor": "white",
           "radialaxis": {
            "gridcolor": "rgb(232,232,232)",
            "linecolor": "rgb(36,36,36)",
            "showgrid": false,
            "showline": true,
            "ticks": "outside"
           }
          },
          "scene": {
           "xaxis": {
            "backgroundcolor": "white",
            "gridcolor": "rgb(232,232,232)",
            "gridwidth": 2,
            "linecolor": "rgb(36,36,36)",
            "showbackground": true,
            "showgrid": false,
            "showline": true,
            "ticks": "outside",
            "zeroline": false,
            "zerolinecolor": "rgb(36,36,36)"
           },
           "yaxis": {
            "backgroundcolor": "white",
            "gridcolor": "rgb(232,232,232)",
            "gridwidth": 2,
            "linecolor": "rgb(36,36,36)",
            "showbackground": true,
            "showgrid": false,
            "showline": true,
            "ticks": "outside",
            "zeroline": false,
            "zerolinecolor": "rgb(36,36,36)"
           },
           "zaxis": {
            "backgroundcolor": "white",
            "gridcolor": "rgb(232,232,232)",
            "gridwidth": 2,
            "linecolor": "rgb(36,36,36)",
            "showbackground": true,
            "showgrid": false,
            "showline": true,
            "ticks": "outside",
            "zeroline": false,
            "zerolinecolor": "rgb(36,36,36)"
           }
          },
          "shapedefaults": {
           "fillcolor": "black",
           "line": {
            "width": 0
           },
           "opacity": 0.3
          },
          "ternary": {
           "aaxis": {
            "gridcolor": "rgb(232,232,232)",
            "linecolor": "rgb(36,36,36)",
            "showgrid": false,
            "showline": true,
            "ticks": "outside"
           },
           "baxis": {
            "gridcolor": "rgb(232,232,232)",
            "linecolor": "rgb(36,36,36)",
            "showgrid": false,
            "showline": true,
            "ticks": "outside"
           },
           "bgcolor": "white",
           "caxis": {
            "gridcolor": "rgb(232,232,232)",
            "linecolor": "rgb(36,36,36)",
            "showgrid": false,
            "showline": true,
            "ticks": "outside"
           }
          },
          "title": {
           "x": 0.05
          },
          "xaxis": {
           "automargin": true,
           "gridcolor": "rgb(232,232,232)",
           "linecolor": "rgb(36,36,36)",
           "showgrid": false,
           "showline": true,
           "ticks": "outside",
           "title": {
            "standoff": 15
           },
           "zeroline": false,
           "zerolinecolor": "rgb(36,36,36)"
          },
          "yaxis": {
           "automargin": true,
           "gridcolor": "rgb(232,232,232)",
           "linecolor": "rgb(36,36,36)",
           "showgrid": false,
           "showline": true,
           "ticks": "outside",
           "title": {
            "standoff": 15
           },
           "zeroline": false,
           "zerolinecolor": "rgb(36,36,36)"
          }
         }
        },
        "title": {
         "font": {
          "color": "Black",
          "size": 22
         },
         "text": "<b>Intertopic Distance Map</b>",
         "x": 0.5,
         "xanchor": "center",
         "y": 0.95,
         "yanchor": "top"
        },
        "width": 1000,
        "xaxis": {
         "anchor": "y",
         "domain": [
          0,
          1
         ],
         "range": [
          -1.9932966113090516,
          21.026789093017577
         ],
         "title": {
          "text": ""
         },
         "visible": false
        },
        "yaxis": {
         "anchor": "x",
         "domain": [
          0,
          1
         ],
         "range": [
          10.000898790359496,
          17.826926946640015
         ],
         "title": {
          "text": ""
         },
         "visible": false
        }
       }
      }
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 各 Topic 間距離圖\n",
    "topic_fig = topic_model.visualize_topics(\n",
    "    top_n_topics=10,\n",
    "    width=1000,\n",
    ")\n",
    "topic_fig"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "1ae26572eda725713d76d5b5539aa0885fd8640fe2af809f71b79ee35a86cf8d"
  },
  "kernelspec": {
   "display_name": "Python 3.7.11 ('bertopic')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.19"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
